

function listjs() {

    //登录信息
    let username = JSON.parse(localStorage.getItem("username1"));
    console.log(username);
    $(".denglu").html("欢迎用户：" + username + "&nbsp;&nbsp;&nbsp;<span id='tuichudenglu'>退出登录</span>");
    $(".denglu11").html("欢迎用户：" + username );
    var userid = JSON.parse(localStorage.getItem("userid"));

    $("#tuichudenglu").click(function () {
        location.href = "./index.html";
        localStorage.removeItem("username1");
    })

    $(".mycart").click(function () {
        location.href = "html/cart.html";
    });

    function daojishi(oDate2) {
        let daojishitxt = document.getElementById("daojishitxt");
        let djs = daojishitxt.children;
        let oDate1 = new Date();

        let ss = Math.floor((oDate2 - oDate1) / 1000);


        let Hours = Math.floor(ss / 3600 % 24);
        let Minute = Math.floor(ss / 60 % 60);
        let Seconds = Math.floor(ss % 60);
        Seconds = Seconds < 10 ? "0" + Seconds : Seconds;
        Minute = Minute < 10 ? "0" + Minute : Minute;
        Hours = Hours < 10 ? "0" + Hours : Hours;
        djs[0].innerText = Hours;
        djs[1].innerText = Minute;
        djs[2].innerText = Seconds;

    };

    function biglunbo() {
        let count = 0;
        let timer1 = null;
        let $btn = $("#bigbtn>button");
        let $slb = $("#blbt>li");
        slider();
        $("#biglunbo").hover(function () {
            clearInterval(timer1);
            $("#blbs li").mouseover(function () {
                let oIndex = $(this).index();
                $("#blbs li").eq(oIndex).addClass("select").siblings().removeClass("select");
                $("#blbt li").eq(oIndex).stop().fadeIn(500)
                    .siblings().fadeOut(500);
            })
            $btn.eq(0).click(function () {
                count--;
                if (count == -1) {
                    count = $slb.length - 1;
                };
                $("#blbt li").eq(count).fadeIn(800)
                    .siblings().fadeOut(800);
                $("#blbs li").eq(count).addClass("select").siblings().removeClass("select");

            });
            $btn.eq(1).click(function () {
                count++;
                if (count == $slb.length) {
                    count = 0;
                };
                $("#blbt li").eq(count).fadeIn(800)
                    .siblings().fadeOut(800);
                $("#blbs li").eq(count).addClass("select").siblings().removeClass("select");
            });

        }, function () {
            slider();
        });

        function slider() {
            timer1 = setInterval(function () {
                count++;
                if (count == $("#blbt li").length) {
                    count = 0;
                }
                $("#blbt li").eq(count).fadeIn(800)
                    .siblings().fadeOut(800)
                $("#blbs li").eq(count).addClass("select").siblings().removeClass("select")

            }, 3000);
        }





    };

    function smalunbo() {
        let count = null;
        let timer2 = null;
        let $btn = $("#smalunbo>div>button");
        let $slb = $("#smalunbo>ul>li");
        move();
        $("#smalunbo").hover(function () {
            clearInterval(timer2);
            $btn.show();
            $btn.eq(0).click(function () {
                count--;
                if (count == -1) {
                    count = $slb.length - 1;
                };
                $slb.eq(count).show().siblings().hide();

            });
            $btn.eq(1).click(function () {
                count++;
                if (count == $slb.length) {
                    count = 0;
                };

                $slb.eq(count).show().siblings().hide();
            });
        }, function () {
            $btn.hide();
            move();
        });



        function move() {
            timer2 = setInterval(function () {
                count++;
                if (count == $slb.length) {
                    count = 0;
                }
                $slb.eq(count).show().siblings().hide();
            }, 2000);
        }





    };

    function louti() {

        $(window).scroll(function () {
            let scro = $(window).scrollTop();
            let st = $(".miaosha").offset().top;
            let jlt = Math.abs(scro - st);
            if (st <= scro) {
                $(".tiaozhuan").css({
                    "top": scro - 600 + "px",
                });
                $(".tiaozhuan-7").show();
            } else {
                $(".tiaozhuan").css({
                    "top": 0,
                });
                $(".tiaozhuan-7").hide();
            }
        })


    }

    //倒计时
    var oDate = new Date("2021-09-1 12:00:00");
    daojishi(oDate);
    var timer = setInterval(function () {
        daojishi(oDate);
    }, 1000);

    //轮播
    // $("#biglunbo")
    biglunbo();
    smalunbo();
    louti();







    //  Initialize Swiper
    var swiper1 = new Swiper('.swiper-container-1', {
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
        loop: true,
        autoplay: {
            delay: 3000,
        },
        hashNavigation: true,
    });



    let swiper2 = new Swiper('.swiper-container-2', {
        slidesPerGroup: 4,
        slidesPerView: 4,
        spaceBetween: 2,
        autoplay: false,
        loop: false,
        navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
        },
        pagination: {
            //   el: '.swiper-pagination',
            // clickable: true,
        },
    });





    //上传数据：到 用户"38306"
    $(".shangchuanshuju").click(function () {
        location.href = "html/addproduct.html"
    });



    //秒杀轮播图
    $.ajax({
        type: "get",
        url: "http://jx.xuzhixiang.top/ap/api/productlist.php",
        data: {
            uid: userid,
        },
        success: function (data) {
            var data = data.data;
            var str = "";
            for (var i = 0; i < data.length; i++) {
                str = `
                    <div class="mslbt">
                        <img data-id="${data[i].pid}" src="${data[i].pimg}" alt="">
                        <p>${data[i].pname}</p>
                        <div>
                            <span><i>￥</i><span>${data[i].pprice}</span></span>
                            <span><i>￥</i><span>80.00</span></span>
                        </div> 
                    </div>                                                  
                `;

                $(".xueluner").eq(i).html(str);
            };
            //点击进入详情页
            $(".mslbt").click(function () {
                console.log("a");
                var prodid = $(this).find("img").data("id");
                location.href = "html/detail.html?pid=" + prodid;
            });
        }
    });

    //快来抢购吧！！！
    $.ajax({
        type: "get",
        url: "http://jx.xuzhixiang.top/ap/api/productlist.php",
        data: {
            uid: userid,
        },
        success: function (data) {
            var data = data.data;
            var str1 = "";
            for (var i = 0; i < 18; i++) {
                str1 += `
                    <div class="klqgb">
                        <img data-id="${data[i].pid}" src="${data[i].pimg}" alt="">
                        <p>快来抢购吧</p>
                        <div>￥9.9</div>
                    </div>     
                `;
            };
            $(".pindao-main").html(str1);
            //点击进入详情页
            $(".klqgb").click(function () {
                var prodid = $(this).find("img").data("id");
                console.log(prodid);
                location.href = "html/detail.html?pid=" + prodid;
            });

        }
    });


    //为你推荐啦啦！！！  //动画   //新品
    $.ajax({
        type: "get",
        url: "http://jx.xuzhixiang.top/ap/api/productlist.php",
        data: {
            uid: userid,
        },
        success: function (data) {
            var data = data.data;
            var str = "";
            var str7 = "";
            var str1 = "";
            for (var i = 0; i < data.length; i++) {
                str += `
                    <div class="wntjlll" data-id="${data[i].pid}">
                        <img src="${data[i].pimg}" alt="">
                        <p>${data[i].pname}</p>
                        <div>
                            <span><i>￥</i><span>${data[i].pprice}</span></span>
                            <span><i>￥</i><span>80.00</span></span>
                        </div> 
                    </div>     
                `;

            };
            for (var i = 5; i < data.length; i++) {
                str7 += `
                <li class="dh-1" data-id="${data[i].pid}">
                    <img src="${data[i].pimg}" alt="图片">
                    <p> 商品：${data[i].pname}</p>
                    <p> ￥${data[i].pprice}</p>
                </li>
            `; 
            };
            for(var i=9;i<13;i++){
                str1 += `
                <div data-id="${data[i].pid}">
                    <img src="${data[i].pimg}" alt="">
                    <p>商品：${data[i].pname}</p>
                    <p>￥${data[i].pprice}</p>
                </div>
                `;
            }
            $(".weini-main").html(str);
            $("#donghua").html(str7);
            $(".xinpin").html(str1);

            $(".wntjlll").click(function () {
                console.log("a");
                var prodid = $(this).data("id");
                location.href = "html/detail.html?pid=" + prodid;
            });

            $("#donghua>li").click(function () {
                var prodid = $(this).data("id");
                location.href = "html/detail.html?pid=" + prodid;

            });
            $(".xinpin>div").click(function () {
                var prodid = $(this).data("id");
                location.href = "html/detail.html?pid=" + prodid;

            });



        },
    });


    $.ajax({
        type: "get",
        url: "http://jx.xuzhixiang.top/ap/api/productlist.php",
        data: {
            uid: userid,
        },
        success: function (data) {

            var data = data.data;
            var str1 = "";
            var str2 = "";
            var str3 = "";
            var str4 = "";
            var str5 = "";
            var str6 = "";
            for (var i = 0; i < data.length; i++) {

                if (i >= 0 && i < 5) {
                    str1 += `
                    <div class="detailpage" data-id="${data[i].pid}">
                        <img src="${data[i].pimg}" alt="">
                        <p>商品：${data[i].pname}</p>
                        <p>￥${data[i].pprice}</p>
                    </div>        
                `;
                }
                if (i >= 8 && i < 13) {
                    str5 += `
                    <div class="detailpage"  data-id="${data[i].pid}">
                        <img src="${data[i].pimg}" alt="">
                        <p>商品：${data[i].pname}</p>
                        <p>￥${data[i].pprice}</p>
                    </div>        
                `;
                }
                if (i >= 5 && i < 10) {
                    str2 += `
                    <div class="detailpage" data-id="${data[i].pid}">
                        <img src="${data[i].pimg}" alt="">
                        <p>商品：${data[i].pname}</p>
                        <p>￥${data[i].pprice}</p>
                    </div>        
                `;
                }
                if (i >= 10 && i < 15) {
                    str3 += `
                    <div class="detailpage"  data-id="${data[i].pid}">
                        <img src="${data[i].pimg}" alt="">
                        <p>商品：${data[i].pname}</p>
                        <p>￥${data[i].pprice}</p>
                    </div>        
                `;
                }
                if (i >= 15 && i < 20) {
                    str4 += `
                    <div class="detailpage" data-id="${data[i].pid}">
                        <img src="${data[i].pimg}" alt="">
                        <p>商品：${data[i].pname}</p>
                        <p>￥${data[i].pprice}</p>
                    </div>        
                `;
                }
                if (i >= 0 && i < 8) {
                    str6 += `
                    <li data-id="${data[i].pid}"><img src="${data[i].pimg}"></li>
                    `;
                };


            };
            $(".main-1").html(str1);
            $(".main-2").html(str2);
            $(".main-3").html(str3);
            $(".main-4").html(str4);
            $(".main-5").html(str5);
            $("#blbt").html(str6);


            $(".detailpage").click(function () {
                var prodid = $(this).data("id");
                console.log("aa")
                location.href = "html/detail.html?pid=" + prodid;

            });
            $("#blbt>li").click(function () {
                var prodid = $(this).data("id");
                location.href = "html/detail.html?pid=" + prodid;

            });





        }
    });





    //
    $(".banner1>.list>li").hover(function () {
        $(".banner1>.mobaner").show();
    }, function () {
        $(".banner1>.mobaner").hide();
    });
    $(".banner1>.mobaner").hover(function () {
        $(this).show();
    }, function () {
        $(this).hide();
    });
    $(".meririlist>li").hover(function () {
        $(this).addClass("meirihover").siblings().removeClass("meirihover");
        var oindex = $(this).index();
        $(".main>div").eq(oindex).show().siblings().hide();
    });

    $(".meririlist>li").hover(function () {
        console.log("aa")
        $(this).addClass("meirihover").siblings().removeClass("meirihover");
        var oindex = $(this).index();
        $(".main>div").eq(oindex).show().siblings().hide();
    });


    //显示商品总数量

    $.ajax({
        url: "http://jx.xuzhixiang.top/ap/api/cart-list.php",
        type: "get",
        data: {
            id: userid,
        },
        success: function (data) {
            var data = data.data;
            var num = 0;
            for (var i = 0; i < data.length; i++) {
                num += +data[i].pnum;

            };
            $("#xssl").html(num);
        }
    });


    //返回快捷键



    $(window).scroll(function () {
        var t1 = $(".weini").offset().top;
        var t2 = $(".pindao").offset().top;
        var t3 = $(".tejia").offset().top;
        var t4 = $(".miaosha").offset().top;
        $(".tiaozhuan-7").click(function () {
            $(window).scrollTop(0);
        });
        $(".tiaozhuan-4").click(function () {

            $(window).scrollTop(t1);
        });
        $(".tiaozhuan-3").click(function () {

            $(window).scrollTop(t2);
        });
        $(".tiaozhuan-2").click(function () {

            $(window).scrollTop(t3);
        });
        $(".tiaozhuan-1").click(function () {

            $(window).scrollTop(t4);
        });
      /*   if(t2>= $(window).scrollTop() && t3< $(window).scrollTop()){
            $(".tiaozhuan-2").css({
                "background":"red",
            })
        }; */
        /* if(t3>= $(window).scrollTop()&&t4< $(window).scrollTop()){
            $(".tiaozhuan-3").css({
                "background":"red",
            }).siblings.css({
                "background":"white",
            })
        }; */
    });















};












